package com.key.win.business.chat.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.key.win.business.chat.model.ImMessageDetail;
import com.key.win.business.chat.vo.ImSystemMessageFullVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ImMessageDetailDao extends BaseMapper<ImMessageDetail> {

    @Update({"update im_message_detail d set d.status = 1 ${ew.customSqlSegment}"})
    int updateImMessageStatus(@Param("ew") Wrapper<ImMessageDetail> queryWrapper);

    @Select({"SELECT * FROM (SELECT md.*, m.content, m.content_Type, fu.head_img_url AS from_user_avatar, fu.nick_name AS from_user_nick_name, me.head_img_url AS to_user_avatar, me.nick_name AS to_user_nick_name FROM im_message_detail md INNER JOIN im_message m ON md.message_Id = m.id AND md.target = 3 AND md.type = 32 INNER JOIN sys_user me ON md.to_User_Id = me.id INNER JOIN sys_user fu ON md.from_User_Id = fu.id) imd ${ew.customSqlSegment}"})
    List<ImSystemMessageFullVo> findSystemMessage(@Param("ew") Wrapper<ImMessageDetail> queryWrapper);
}
